#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<unistd.h>
#include<signal.h>
#include<sys/time.h>

int aNum=0;
void signalHandler(int siganlNo){
    printf("signalNo:%d,aNum=%d\n",siganlNo,aNum);
}
long calSum(int end){
    int ans=0;
    for(int i=0;i<=end;++i){
        ans +=i;
    }
    return ans;
}
int main(){
    struct itimerval tm;
    tm.it_interval.tv_sec =1;
    tm.it_interval.tv_usec=0;
    tm.it_value.tv_sec=2;
    tm.it_value.tv_usec=0;
    signal(SIGALRM,signalHandler);
    setitimer(ITIMER_REAL,&tm,NULL);
    for(int i=0;i<100;i++){
        if(i%2==0) usleep(500000);
        aNum= calSum(i);
    }

}